//
//  TCM_AuctionBottomView.swift
//  TCM_TradingProject
//  拍卖详情底部操作视图
//
//  Created by xiaofeiZhang on 2018/8/29.
//  Copyright © 2018年 lvchunhai. All rights reserved.
//

import UIKit
import SnapKit
import RxCocoa
import RxSwift

class TCM_AuctionBottomView: UIView {
    let disposeBag = DisposeBag()

    private lazy var bondBtn: UIButton = {
        
        let bondBtn = UIButton.init(type: .custom)
        bondBtn.setTitle("缴纳保证金", for: .normal)
        bondBtn.backgroundColor = TCM_HexRGB(0xF96805)
        bondBtn.titleLabel?.font = TCM_SystemFont(18.0)
        bondBtn.setTitleColor(UIColor.white, for: .normal)
        
        
        return bondBtn
    }()
    
    private lazy var offerBtn: UIButton = {
        
        let offerBtn = UIButton.init(type: .custom)
        offerBtn.setTitle("报价", for: .normal)
        offerBtn.backgroundColor = TCM_HexRGB(0xFAA105)
        offerBtn.titleLabel?.font = TCM_SystemFont(18.0)
        offerBtn.setTitleColor(UIColor.white, for: .normal)
        return offerBtn
    }()
    
    static let instance: TCM_AuctionBottomView = TCM_AuctionBottomView()
    
    class func sharedInstance() -> TCM_AuctionBottomView {
        return instance
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setupSubViews()
        self.setupControl()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate func setupSubViews() {
        self.addSubview(bondBtn)
        self.addSubview(offerBtn)
        
        self.setupConstraint()
    }
    
    fileprivate func setupConstraint() {
        bondBtn.snp.makeConstraints({ (make) in
            make.leading.bottom.top.equalTo(0)
            make.width.equalTo(self.snp.width).multipliedBy(0.5)
        })
        
        offerBtn.snp.makeConstraints({ (make) in
            make.trailing.bottom.top.equalTo(0)
            make.width.equalTo(bondBtn.snp.width)
        })
    }
    
}

extension TCM_AuctionBottomView {
    
    fileprivate func setupControl() {
        bondBtn.rx.tap.subscribe(onNext: { [weak self] in
            print("缴纳保证金")
        }).disposed(by: disposeBag)
        
        offerBtn.rx.tap.subscribe(onNext: { [weak self] in
            print("报价")
        }).disposed(by: disposeBag)
    }
}
